package com.pocket.demo.core.mq.rabbitMQ.demo;

import cn.hutool.json.JSONUtil;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.MessageHeaders;

/**
 * @author cookie.
 **/
public class DirectConsumer {

    private static final Logger LOGGER = LoggerFactory.getLogger(DirectConsumer.class);

    @RabbitListener(queues = DirectExchangeConfig.DIRECT_QUEUE_1)
    public void listenDirectErrorQueueMessage(String msg){
        LOGGER.debug("RabbitMQ (only payload): received message from {} - {} ：{}", DirectExchangeConfig.DIRECT_QUEUE_1, DirectExchangeConfig.DIRECT_ROUTING_ERROR_KEY, msg);
    }

    @RabbitListener(queues = DirectExchangeConfig.DIRECT_QUEUE_2)
    public void listenDirectWarnQueueMessage(String msg, MessageHeaders messageHeaders){
        LOGGER.debug("RabbitMQ （part params）: received message from {} - {} ：{}", DirectExchangeConfig.DIRECT_QUEUE_2, DirectExchangeConfig.DIRECT_ROUTING_WARN_KEY, msg);
        LOGGER.debug("RabbitMQ （part params）: listener received param [parameters]：{}", JSONUtil.toJsonStr(messageHeaders));
    }

    @RabbitListener(queues = DirectExchangeConfig.DIRECT_QUEUE_2)
    public void listenDirectWarnQueueMessage(Message amqpMessage, Channel channel, MessageProperties messageProperties){
        LOGGER.debug("RabbitMQ （all params）: listener received param [amqpMessage]：{}", JSONUtil.toJsonStr(amqpMessage));
        LOGGER.debug("RabbitMQ （all params）: listener received param [channel]：{}", JSONUtil.toJsonStr(channel));
        LOGGER.debug("RabbitMQ （all params）: listener received param [messageProperties]：{}", JSONUtil.toJsonStr(messageProperties));
    }




}
